
** Figure H.19: Consumption placebos

foreach timevariable in 14 15 16 17 18 19 20 21 22 23 24 25 26{
use "$datadir/consumption/finaldata_log_hh_regression_all", clear
		merge m:1 state district using "$datadir\districts\districts_crosswalk.dta"
		drop if _m == 2
		drop _m
		replace state = state_census2001
		replace district = district_census2001
		drop state_census2011 district_census2011 state_census2001 district_census2001
		replace district = trim(district)
		replace state = trim(state)
				
		gen xtime = time_id
		replace time_id = xtime +(33-`timevariable')
		gen xtime_survey = time_survey_id
		replace time_survey_id = xtime_survey +(34-`timevariable')
		
		do "$superdir/code/stata/build/create_HH_data_all.do" 		// Do everthing in terms of time_id
		
		** Merge with district banking data
		keep if time_survey_id >= 15 & time_survey_id <= 50
		xtset HH_ID time_id
		
		
		g event_time = .
		replace event_time = -4 if time_survey_id >= 15 & time_survey_id <= 18
		replace event_time = -3 if time_survey_id >= 19 & time_survey_id <= 22
		replace event_time = -2 if time_survey_id >= 23 & time_survey_id <= 26
		replace event_time = -1 if time_survey_id >= 27 & time_survey_id <= 30
		replace event_time = 0 if time_survey_id >= 31 & time_survey_id <= 34
		replace event_time = 1 if time_survey_id >= 35 & time_survey_id <= 38
		replace event_time = 2 if time_survey_id >= 39 & time_survey_id <= 42
		replace event_time = 3 if time_survey_id >= 43 & time_survey_id <= 46
		replace event_time = 4 if time_survey_id >= 47 & time_survey_id <= 50
		
		keep if event_time >= -2 & event_time <= 2
		
		gen EXPENSE_ON_ALLRECREATION=EXPENSE_ON_RESTAURANT+EXPENSE_ON_RECREATION+EXPENSE_ON_INTOXICANTS
		gen EXPENSE_ON_FREQUENT=TOTAL_EXPENDITURE-EXPENSE_ON_INFREQUENT

		
		collapse (mean) TOTAL_EXPENDITURE EXPENSE_ON_NECESSARY EXPENSE_ON_UNNECESSARY EXPENSE_ON_FREQUENT EXPENSE_ON_INFREQUENT EXPENSE_ON_ALLRECREATION EXPENSE_ON_RECREATION EXPENSE_ON_FOOD EXPENSE_ON_HEALTH  ///
		log_mrain_adj l_income_pre l_age_pre , by(HH_ID event_time district state)
		
		
		gen log_hh_expense_total = ln(TOTAL_EXPENDITURE)
		gen log1_hh_expense_necessary = ln(EXPENSE_ON_NECESSARY+1)
		gen log1_hh_expense_unnecessary=ln(EXPENSE_ON_UNNECESSARY+1)
		gen log1_hh_expense_infrequent = ln(EXPENSE_ON_INFREQUENT+1)
		gen log1_hh_expense_frequent=ln(EXPENSE_ON_FREQUENT+1)
		gen log1_hh_expense_ALLrecreation=ln(EXPENSE_ON_ALLRECREATION+1)
		gen log1_hh_expense_recreation=ln(EXPENSE_ON_RECREATION+1)
		gen log1_hh_expense_food=ln(EXPENSE_ON_FOOD+1)
		gen log1_hh_expense_health=ln(EXPENSE_ON_HEALTH+1) 
		
		
		egen district_id = group(district state)
		
		g post_new = event_time >= 1
		tab post_new
		
	
		xtset HH_ID event_time
		
		cap drop dep_ad_last_2years
		cap drop invshare_sd
		cap drop l_preshockdeposit
		
		
		** add banking deposit data
		merge m:1  state district using "$datadir/banking/adjusted_deposit.dta", keepusing(state district dep_ad_last_2years preshock_deposit) keep(match) nogenerate 
		**
		g l_preshockdeposit = ln(1+preshock_deposit)
		label var l_preshockdeposit "Log(pre-shock deposits)"
		
		** attach 2011 district controls
		merge m:1 district state using "$datadir\districts\districtcontrols.dta", update replace
		drop if (_m == 1 | _m == 2)
		drop _m
		**
		
		* merge with new chest measure (invshare_td and invshare_sd) 
		merge m:1 district state using "$datadir\banking\chest_exposure_full.dta", keepusing(state district invshare_sd) keep(match) nogenerate 
		
		gen treat0=(event_time==0)
		gen treat1=(event_time==1)
		gen treat2=(event_time==2)
		
		forval i=1/2{
			g treat`i'Xdeposit = treat`i'*dep_ad_last_2years
			g treat`i'Xinvshare_sd = treat`i'*invshare_sd
		}
		
		forval i=1/5{
		local j = `i'-3
		g time`i'Xdeposit = (event_time == `j')*dep_ad_last_2years
		g time`i'Xinvshare_sd = (event_time == `j')*invshare_sd	
		}
		replace time3Xdeposit = 0 
		replace time3Xinvshare_sd = 0 
		
		** each post-treatment event time separately
		
			
			***** FIGURES
		  cap mkdir "$outputdir\Tables\new_chest\"
		  cap mkdir "$outputdir\Tables\new_chest\temp\"
		  cap mkdir "$outputdir\Figures\"
		  cap mkdir "$outputdir\Figures\new_chest\"
	  
		  *regression
		  local controls "(c.log_mrain_adj c.l_income_pre c.l_age_pre c.l_preshockdeposit c.s_status_atm c.s_status_commercialbank c.logpop_T c.share_rural)"
		  foreach var of varlist log_hh_expense_total log1_hh_expense_necessary log1_hh_expense_unnecessary  log1_hh_expense_frequent log1_hh_expense_infrequent log1_hh_expense_ALLrecreation log1_hh_expense_food {
			statsby eff_1=_b[time1Xinvshare_sd] eff_2=_b[time2Xinvshare_sd] eff_3=_b[time3Xinvshare_sd] eff_4=_b[time4Xinvshare_sd] eff_5=_b[time5Xinvshare_sd] se_1 =_se[time1Xinvshare_sd] se_2 =_se[time2Xinvshare_sd] se_3 = _se[time3Xinvshare_sd] se_4 =_se[time4Xinvshare_sd] se_5 =_se[time5Xinvshare_sd] , saving("$datadir\bin\coefsSHIF_contr_`var'_rf_survey_placebos_`timevariable'", replace): reghdfe `var' time1Xinvshare_sd time2Xinvshare_sd time3Xinvshare_sd time4Xinvshare_sd time5Xinvshare_sd, a(HH_ID i.event_time `controls'##i.event_time) vce(cluster district_id)
		  }
 }
 


foreach var in log_hh_expense_total {
	foreach timevariable in 14 15 16 17 18 19 20 21 22 23 24 25 26{
		use "$datadir\bin\coefsSHIF_contr_`var'_rf_survey_placebos_`timevariable'.dta", clear
		keep eff_4 se_4 
		rename eff_4 eff
		rename se_4 se
		gen time=`timevariable'
		save temp`timevariable'.dta, replace
	}
 
	clear
	set obs 1
	forval timevariable = 14/26{
		append using temp`timevariable'.dta
		erase temp`timevariable'.dta
	}
 
	gen t_10=1.65
	gen t_5=1.96  
	foreach num in 5 10 {
		gen low_bound_`num'=eff-(t_`num'*se)
		gen up_bound_`num'=eff+(t_`num'*se)
	}
	
	gen temp="`var'"
	local name="`var'"
	if temp=="log_hh_expense_total" {
	  local name="Total Consumption"
	}
	
  twoway (rcap up_bound_5 low_bound_5 time, lcolor(gray) lstyle(ci)) (scatter eff time, lcolor(black) mcolor(black) msymbol(circle) msize(medium)) , ///
  legend(off) graphregion(color(white)) ylab(,nogrid) xlabel(14(1)26) yline(0, lcolor(gs12) lpattern(dash)) ///
  xtitle("Placebo Survey-time") ytitle("Effect on `name'") xlabel(14 "Feb-15" 17 "May-15" 20 "Aug-15" 23 "Nov-15" 26 "Feb-16", labsize(small))
  graph export "$outputdir_fig\Figure_H_19.pdf",  as(pdf) replace
 }

 foreach var in log_hh_expense_total {
	foreach timevariable in 14 15 16 17 18 19 20 21 22 23 24 25 26{
		erase "$datadir\bin\coefsSHIF_contr_`var'_rf_survey_placebos_`timevariable'.dta"
	}
}
